package by.grsu.transport.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

@SuppressWarnings("serial")
public class LoginForm extends ActionForm {

	/**
	 * 
	 */
	private String login;
	private String password;
	
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		 ActionErrors actionErrors = new ActionErrors();
		 
	        if((login == null) || (login.trim().equals(""))) {
	            actionErrors.add("login", new ActionMessage("error.login", login));
	        }
	        
	        try {
		        if((password == null) || (password.trim().equals(""))) {
		            actionErrors.add("password", new ActionMessage("error.password"));
		        }
	        } catch(Exception e) {
	            // use logger here
	        }
	        
	        return actionErrors;
    }
	
	public void reset(ActionMapping mapping, HttpServletRequest request) {
        this.login = null;
        this.password = null;
        super.reset(mapping, request);
    }
	
}
